#include "buttonitem.h"
#include <QDebug>

ButtonItem::ButtonItem(const QString &imgName,
                       const QPoint &leftTop,
                       const QPoint &rightBottom,
                       QGraphicsScene *scene,
                       QGraphicsItem *parent) :
    ImageItem(imgName, leftTop, rightBottom, scene, parent), focused(false)
{
    this->setAcceptHoverEvents(true);
    this->setEnabled(true);
}

void ButtonItem::setFocusing(bool focus)
{
    focused = focus;
    update();
}

void ButtonItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
    focused = true;
    update();
//    this->setVisible(true);
}

void ButtonItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
    focused = false;
    update();
//    this->setVisible(false);
}

void ButtonItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
//    qDebug() << event->pos();
}

void ButtonItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
    setFocusing(false);
    emit clicked(this);
}

void ButtonItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    if (focused)
        ImageItem::paint(painter, option, widget);
    else
    {}
}
